<template>
  <div class="popover-layout">
    <div @[trigger].stop="onActive" class="action">
      <slot />
    </div>

    <transition name="van-fade">
      <div v-show="visible" class="content">
        <slot name="content" />
        <div class="dot" />
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  props: {
    trigger: {
      type: String,
      default: 'click'
    }
  },

  data() {
    return {
      visible: false
    }
  },

  methods: {
    onActive() {
      this.visible = !this.visible
    }
  }
}
</script>

<style lang="less" scoped>
.popover-layout {
  position: relative;

  .content {
    position: absolute;
    left: -50%;
    z-index: 1;
    margin-top: 16px;
    background-color: #ffffff;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    text-align: center;

    .dot {
      position: absolute;
      top: -16px;
      left: calc(50% - 8px);
      width: 0;
      height: 0;
      border-width: 8px;
      border-style: solid;
      border-color: transparent transparent #ffffff transparent;
    }
  }
}
</style>